package cha;

import static org.junit.Assert.assertEquals;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.testing.RobotTestBed;

/**
 * Test if Destroyer always defeats SittingDuck,
 * the most basic robot.
 * 
 * @author Hansen Cheng
 *
 */
public class TestDestroyerVersusSittingDuck extends RobotTestBed {

  /**
   * Specifies that SittingDuck and Destroyer are the 
   * robots participating in this battle.
   * 
   * @return The list of robot names in this battle.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,cha.Destroyer";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * Test if Destroyer robot have won every round against
   * SittingDuck robot.
   * 
   * @param event - catches the details after end of battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    BattleResults[] battleResults = event.getIndexedResults();
    BattleResults destroyerResults = battleResults[1];
    String robotName = destroyerResults.getTeamLeaderName();
    assertEquals("Check that results[1] is Destroyer", robotName, "cha.Destroyer*");
    
    // Check to make sure Destroyer won every round.
    assertEquals("Check Destroyer winner", destroyerResults.getFirsts(), getNumRounds());
  }
  
  
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // You could add code here to check a condition after every turn or collect data. 
  }
  
  
  @Override
  public String getInitialPositions() {
    return null;
  }
  
  
  @Override
  public boolean isDeterministic() {
    return true;
  }

  
  @Override
  protected int getExpectedErrors() {
    return 0;
  }
  
  
  @Override
  protected void runSetup() {
    // Default does nothing.
  }

 
  @Override
  protected void runTeardown() {
    // Default does nothing.
  }
  

}
